<?php
/**[模型控制器]
 * @Author: 976123967@qq.com
 * @Date:   2014-09-22 15:45:01
 * @Last Modified by:   chen
 * @Last Modified time: 2014-10-28 22:35:22
 */
class ModelAction extends PublicAction{

	public function _initialize()
	{
		parent::_initialize();
		$this->model = D('Model');
	}

	/**
	 * [index 所有模型列表]
	 * @return [type] [description]
	 */
	public function index()
	{

		$data = $this->model->get_model_all();
		$this->assign('data',$data);
		$this->display();
	}

	/**
	 * [add 添加模型]
	 */
	public function add()
	{
		if(IS_POST)
		{
			if(!$this->model->create()) $this->error($this->model->getError());
			$this->model->add_model();
			$this->success('模型添加成功',U('Model/index'));
			die;
		}
		$this->display();
	}

	/**
	 * [edit 编辑]
	 * @return [type] [description]
	 */
	public function edit()
	{
		if(IS_POST)
		{
			if(!$this->model->create()) $this->error($this->model->getError());
			$this->model->edit_model();
			$this->success('模型更新成功',U('Model/index'));
			die;
		}
		$mid = I('get.mid',null,'intval');
		$field = $this->model->find_one($mid);
		$this->assign('field',$field);
		$this->display();
	}

	/**
	 * [del 删除模型]
	 * @return [type] [description]
	 */
	public function del()
	{
		$mid = I('get.mid',null,'intval');
		$this->model->del_model($mid);
		$this->success('模型删除成功',U('Model/index'));
	}


	/**
	 * [update_cache 更新缓存]
	 * @return [type] [description]
	 */
	public function update_cache()
	{
		$this->model->update_cache();
		$this->success('模型缓存更新成功',U('Model/index'));
	}


}